package main

import "fmt"

func main() {

	s := "支不支持中文呢"
	maxLength := test(s)
	fmt.Println(maxLength)
}

func test(s string) int {

	start := 0
	maxLength := 0
	lastOcurred := make(map[rune]int)
	for k, v := range []rune(s) {

		// 如果当前存在重复则在start之后则更新start位置
		if lastId, ok := lastOcurred[v]; ok && lastOcurred[v] >= start {
			start = lastId + 1
		}

		// 重新计算不具有重复值的长度
		if k-start+1 > maxLength {
			maxLength = k - start + 1
		}
		// 保存已有的值
		lastOcurred[v] = k
	}
	return maxLength
}
